package Code.Objects.Misc;

import org.jrabbit.base.managers.ResourceManager;
import org.jrabbit.standard.game.objects.Sprite;
import org.newdawn.slick.Color;

import Code.Basic.Entity.GenericCharacter;

public class HealingStation extends GenericCharacter
{
	private Sprite cap;
	private Sprite aura;
	
	private static final float maxHealDistance = 400f;
	private static final float minHealDistance = 100f;
	private static final float baseHealing = 0.003f;

	public HealingStation(double x, double y)
	{
		super("Resources/Images/Objects/Healing Station/Healing Station Base.png");
		setToCircle(30);
		body.setMoveable(false);
		body.setRotatable(false);
		
		defineHealth(Float.MAX_VALUE);
		
		shadowXScale = 0.2f;
		shadowYScale = 0.2f;
		
		cap = new Sprite("Resources/Images/Objects/Healing Station/Healing Station Top.png");
		aura = new Sprite("Resources/Images/Objects/Healing Station/Healing Station Glow.png");
		aura.color().set(Color.green);
		aura.scalar().set(1.3f);
		aura.color().setAlpha(0.6f);
		
		this.faction = 1;
		
		setLocation(x, y);
		aura.location().set(x, y);
		cap.location().set(x, y);
	}
	
	public void render()
	{
		super.render();
		aura.rotation().set(ResourceManager.random().nextDouble() * 360);
		aura.render();
		cap.render();
	}
	
	public void update(int delta)
	{
		super.update(delta);
		if(gameWorld != null)
		{
			GenericCharacter target = gameWorld.getPlayer();
			if(target != null)
			{
				double distance = target.location().distanceTo(location);
				if(distance < maxHealDistance)
				{
					target.addHealth((float) ((1 - ((distance - minHealDistance) /
							(maxHealDistance - minHealDistance))) * baseHealing * delta));
				}
			}
		}
	}
}
